# 第一题
# for 循环的简单计数
lst = [1, 2, 3, 4, 5]
for e in lst:
    print(e)
# 获取索引值和值
for x, e in enumerate(lst):
    print(f"index:{x}, value:{e}")

# while 的简单计数
a = 0
while True:
    if a == 100:
        break
    print(a)
    a += 1


# 第二题
# for语句实现斐波那契函数(100以内)
x = 0
y = 1
lst_2 = [x, y]
for n in lst_2:
    n = x + y
    x = y
    y = n
    lst_2.append(n)
    if n >= 100:
        lst_2.pop()
print(lst_2)

# while语句实现斐波那契函数(100以内)
p = 0
q = 1
i = 0
lst_3 = [p, q]
while True:
    if i >= 100:
        break
    i = p + q
    p = q
    q = i
    lst_3.append(i)
lst_3.pop()
print(lst_3)


# 第三题 抛出自定义异常
class ParamsError(Exception):
    pass

def div(c, b):
    try:
        return c / b
    except ZeroDivisionError:
        raise ParamsError("分母不可为0")
    finally:
        print("function div end")

div(1, 0)

